package it.ap.sa.acqua.application.startup;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import it.ap.sa.core.confservice.event.ApplicationEnvironmentSetup;

/**
 * Questa classe è chiamata allo Spring's startup.
 * 
 * @param event Event raised when an {@code ApplicationContext} gets initialized or refreshed.
 * @author Alessandro Paolillo
 */
@Component
public class AcquariumEnvironmentSetup extends ApplicationEnvironmentSetup {

	private static final Logger logger = LoggerFactory.getLogger(AcquariumEnvironmentSetup.class.getName());
	
	/** necessario per evitare di reinizializzare il tutto **/
	static Boolean initilizedAcquarium = false;
	
	/**
	 * This method is called during Spring's startup.
	 * 
	 * @param event
	 *            Event raised when an ApplicationContext gets initialized or
	 *            refreshed.
	 */
	@Override
	public void onApplicationEvent(final ContextRefreshedEvent event) {
		if(!initilizedAcquarium && initilized){
			logger.info(">>>>>>>>>>>>>>>>>>>>>>> Setup dell'ambiente ACQUARIUM ... IN CORSO <<<<<<<<<<<<<<<<< ");
			/* ricorda inizializzazione */
			initilizedAcquarium = true;
			logger.info(">>>>>>>>>>>>>>>>>>>>>>> Setup dell'ambiente ACQUARIUM ... TERMINATO <<<<<<<<<<<<<<<<< ");
		}
	}
}
